<template>
	<view>
		<cu-custom bgColor="bg-white text-black" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">消息中心</block>
		</cu-custom>
		<view class="cu-list menu">
			<view class="cu-item arrow" @tap="goPage('/pages/member/notice/remind')">
				<view class="cu-avatar bg-red round ">
					<text class="cuIcon-notice"></text>
					<view class="cu-tag badge" v-if="statistics && statistics.remind_count>0">{{statistics.remind_count}}</view>
				</view>
				<view class="content">
					<view class="text-black margin-left">系统通知</view>
				</view>
			</view>
		</view>
		<view class="cu-bar  solid-top">
			<view class="action text-lg text-black text-bold">系统公告</view>
		</view>
		<block v-for="(item,index) in list" :key="index">
			<view class="margin-lr margin-bottom bg-white radius " @tap="goDetail(item,index)">
				<image :src="item.cover" v-if="item.cover" mode="widthFix" class="w100"></image>
				<view class="padding-sm text-black text-lg ">
					<view class="cu-tag bg-red radius margin-right-xs" v-if="!item.notifyMember"></view>
					{{item.title}}
				</view>
				<view class="space-between padding-lr-sm padding-bottom">
					<view class="text-gray text-sm">{{$common.timeFormat(item.created_at)}}</view>
				</view>
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		name: "member",
		components: {},
		data() {
			return {
				statistics: null,
				list: [],
				hasMore: true,
				loading: false,
				page: 1
			}
		},
		onLoad(options) {
			if (this.$common.loginAuth(true)) {
				this.getList()
			}
		},
		onShow() {
			if (this.$common.loginAuth(true)) {
				this.$common.rmCache('notice_count')
				this.$common.getNotifyNum().then((num) => {
					this.statistics = num
				})
			}
		},
		methods: {
			getList() {
				if (this.hasMore && !this.loading) {
					this.loading = true
					this.$http
						.get('notice_index', {
							page: this.page,
							type: 1
						})
						.then((response) => {
							let list = this.list
							console.log(response.data.data)
							if (response.data.data.length > 0) {
								if (list.length > 0)
									list = list.concat(response.data.data)
								else list = response.data.data
								this.list = list
							} else {
								this.hasMore = false
							}
							console.log(this.list)
							this.page += 1
							this.loading = false
						})
						.catch((response) => {
							console.log(response)
						})
				}
			},
			goDetail(item, index) {
				this.list[index].notifyMember = 1
				this.$common.rmCache('notice_count')
				uni.navigateTo({
					url: '/pages/member/notice/detail?id=' + item.id
				})
			}
		},
		onReachBottom() {
			this.getList()
		},
	}
</script>

<style>
</style>
